#ifndef __MC33972_H
#define __MC33972_H

#include "main.h"

#include "std.h"


#include <stdint.h>

enum Command
{
    kCMDStatus = 0x00,
    kCMDSettings = 0x01,
    kCMDWakeup1 = 0x02,
    kCMDWakeup2 = 0x03,
    kCMDMetallic1 = 0x04,
    kCMDMetallic2 = 0x05,
    kCMDAnalog = 0x06,
    kCMDWetting1 = 0x07,
    kCMDWetting2 = 0x08,
    kCMDTristate1 = 0x09,
    kCMDTristate2 = 0x0a,
    kCMDCalibration = 0x0b,
    kCMDSleep = 0x0c,
    kCMDReset = 0x7f
};

enum Input{
    kInputSG0   = 0,
    kInputSG1,
    kInputSG2,
    kInputSG3,
    kInputSG4,
    kInputSG5,
    kInputSG6,
    kInputSG7,
    kInputSG8,
    kInputSG9,
    kInputSG10,
    kInputSG11,
    kInputSG12,
    kInputSG13,
    kInputSP0,
    kInputSP1,
    kInputSP2,
    kInputSP3,
    kInputSP4,
    kInputSP5,
    kInputSP6,
    kInputSP7,
    kInputMax
};



typedef struct
{
    uint8_t chan;

    SPI_HandleTypeDef *spix;

    GPIO_TypeDef *gpio_cs;
    uint16_t gpio_pin_cs;
    GPIO_PinState cs_valid;

    
    GPIO_TypeDef *gpio_it;
    uint16_t gpio_pin_it;
    GPIO_PinState it_valid;

    uint8_t err;
    // uint8_t cmd;
    // uint16_t data;
    
    uint32_t in;
} t_mc33972,*p_mc33972;



extern t_mc33972 mc33972_dev[3];

void mc33972_init(p_mc33972 dev, uint8_t chan, SPI_HandleTypeDef *spix, GPIO_TypeDef *gpio_cs, uint16_t gpio_pin_cs, GPIO_PinState cs_valid, GPIO_TypeDef *gpio_it, uint16_t gpio_pin_it, GPIO_PinState it_valid);
void mc33972_conf_init(p_mc33972 dev);
int mc33972_rw(p_mc33972 dev, uint8_t cmd, uint16_t txdata);





#endif


